package service

import (
	"fmt"
	"gitee.com/lanshiren/miniprogram/app/log"
	"gitee.com/lanshiren/miniprogram/app/model"
	"gitee.com/lanshiren/miniprogram/app/stats"
	"strconv"
)

// GetStatusItem...
func GetStatusItem(name string) string {
	status, err := model.GetGlobalStatus()
	if err != nil {
		log.MainLogger.Error(fmt.Sprintf("get global status err %v", err))
	}
	for _, s := range status {
		if s.Name == name {
			return s.V
		}
	}
	return ""
}

// FetchStatusCycle...
func FetchStatusCycle() error {
	questions := GetStatusItem("Questions")
	qes, _ := strconv.Atoi(questions)
	qps := uint64(qes) - stats.GetLastMysqlQuestion()
	fmt.Println("qps: ", qps)
	stats.SetLastMysqlQuestion(uint64(qes))
	return nil
}
